﻿
// train-simple-musicDlg.h: 头文件
//

#pragma once
#include "UI/CButtonUI.h"
#include "UI/CBitItem.h"
#include <vector>
#include "UI/CListBoxUI.h"
#include "UI/CBitSlider.h"
#include "UI/CProgressSlider.h"
#include "UI/CStaticEx.h"

using std::vector;

// CtrainsimplemusicDlg 对话框
class CtrainsimplemusicDlg : public CDialogEx
{
// 构造
public:
	explicit CtrainsimplemusicDlg(CWnd* pParent = nullptr);	// 标准构造函数

// 对话框数据
#ifdef AFX_DESIGN_TIME
	enum { IDD = IDD_TRAINSIMPLEMUSIC_DIALOG };
#endif

protected:
	virtual void DoDataExchange(CDataExchange* pDX);	// DDX/DDV 支持


// 实现
protected:
	HICON m_hIcon;

	// 生成的消息映射函数
	virtual BOOL OnInitDialog();
	HCURSOR GetSysHandCursor();
	BOOL PreTranslateMessage(MSG* pMsg);
	void OnReleasedcaptureSlider();
	void BuildShareSlider();
	afx_msg void OnPaint();
	void drawBackground(CPaintDC& paintDC);
	LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
	void doubleClickPlayerByListBox(size_t value);
	afx_msg HCURSOR OnQueryDragIcon();
	DECLARE_MESSAGE_MAP()

protected:
	/// <summary>
	///  
	/// </summary>
	CString fileNameByMusic;

	/// <summary>
	/// 音乐编号
	/// </summary>
	UINT mDeviceId;

	// 音量
	size_t volumn;

	// 按钮控件 数据
	CButtonUI mCloseButton;

	/// <summary>
	/// 上一曲
	/// </summary>
	CButtonUI mLastSongButton;


	/// <summary>
	/// 停止与播放
	/// </summary>
	CButtonUI mPlayModeButton;

	/// <summary>
	/// 下一曲
	/// </summary>
	CButtonUI mNextSongButton;

	// // 音量滑动控件
	CBitSlider* mVoiceSlider;

	/// <summary>
	/// 停止与播放图标
	/// </summary>
	size_t playModeIconArray[2];

	/// <summary>
	/// 默认编号标记
	/// </summary>
	bool defaultResourceId;


private:
	HCURSOR			hHandCur;

	CBitItem* lpThumb;

	CBitItem* lpActive;
	CBitItem* lpNormal;


	CBitItem* lpProcessActive;
	CBitItem* lpProcessNormal;

	// 歌曲列表
	vector<CString> songVector;

	// 歌曲列表
	CListBoxUI listBox;

	// 回调函数
	map<size_t, void(CtrainsimplemusicDlg::*)(size_t)> messageCallBack;

	/// <summary>
	/// 歌曲播放进度条
	/// </summary>
	CProgressSlider mProcess;

	/// <summary>
	/// 歌曲毫秒数
	/// </summary>
	ULONG_PTR millisecond;

	/// <summary>
	///  当前播放时间控件
	/// </summary>
	CStaticEx currentStaticTextTime;

	/// <summary>
	/// 音量显示控件
	/// </summary>
	CStaticEx activeByVoice;

	/// <summary>
	///  总时间控件
	/// </summary>
	CStaticEx totaltaticTextTime;

	/// <summary>
	/// 当前播放位置
	/// </summary>
	size_t currentPostion;

	CMenu addSongMenu;

	bool loadAddSongMenu;

public:
	
	afx_msg void OnBnClickedOpen();
	void setCurentSong(const CString& const str);
	
	afx_msg void OnBnClickedPlay();


	
	afx_msg void OnBnClickedSuspend();
	afx_msg void OnBnClickedStop();
	afx_msg void OnNMCustomdrawSlider(NMHDR* pNMHDR, LRESULT* pResult);

	afx_msg void OnTimer(UINT_PTR nIDEvent);
	/// <summary>
	/// 绘制控件颜色
	/// </summary>
	/// <param name="pDC"></param>
	/// <param name="pWnd"></param>
	/// <param name="nCtlColor"></param>
	/// <returns></returns>
	HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
	
	/// <summary>
	/// 设置音量
	/// </summary>
	/// <param name="volum"></param>
	void setVolumn(size_t volum);
	
	virtual ~CtrainsimplemusicDlg();
	afx_msg LRESULT OnNcHitTest(CPoint point);
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	afx_msg void OnBnClickedClose();

	afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
	 
	afx_msg void OnBnClickedAddFolder();
	bool IsSupportFile(const CString& fileName);
	void scanFiles(const CString& folder);

	/// <summary>
	/// 添加菜单
	/// </summary>
	afx_msg void onBnClickedAddMenu();
	 
private:

	/// <summary>
	/// 获取歌曲信息 error 0 为正确
	/// </summary>
	/// <param name="dwItem"></param>
	/// <param name="error"></param>
	/// <returns></returns>
	UINT_PTR getMusicInfoItem(size_t dwItem, int* error);

	void getTotalTime(size_t millisecond, CString* timeStr) const;

	/// <summary>
	/// 设置当前播放进度
	/// </summary>
	/// <param name="currentPostion"></param>
	void setCurrentPlayPostion(size_t currentPostion);

	/// <summary>
	/// 设置播放图标
	/// </summary>
	void setPlayModeIcon();

	/// <summary>
	/// 改变清理音乐菜单状态
	/// </summary>
	void editClearStatus();

	
};
